package com.chinasofti.controller;

import com.chinasofti.service.DepartmentService;
import com.chinasofti.vo.Department;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/viewAllDepartmentServlet")
public class ViewAllDepartmentServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {

        String code = request.getParameter("code");
        DepartmentService service = new DepartmentService();
        List<Department> departmentList = service.viewAllDepartments();

        request.setAttribute("departmentList",departmentList);

        if(code != null && code.equals("register")){
            request.getRequestDispatcher("register.jsp").forward(request,resp);
        }
        if(code != null && code.equals("viewalldepts")){
            request.getRequestDispatcher("departments.jsp").forward(request,resp);
        }
    }
}